package com.program.facesigninsystem.config;

import com.program.facesigninsystem.enums.RabbitEnum;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public RabbitTemplate jacksonRabbitTemplate(ConnectionFactory connectionFactory) {

        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
        rabbitTemplate.setReplyTimeout(600000L);

        return rabbitTemplate;
    }

    @Bean
    public TopicExchange faceTopic() {
        return ExchangeBuilder.topicExchange(RabbitEnum.register_face.getExchange()).build();
    }

    @Bean
    public Queue registerQueue() {
        return new Queue(RabbitEnum.register_face.getName());
    }

    @Bean
    public Queue compareQueue() {
        return new Queue(RabbitEnum.compare_face.getName());
    }

    @Bean
    public Binding registerBinding(Queue registerQueue, Exchange faceTopic) {
        return BindingBuilder.bind(registerQueue)
                .to(faceTopic)
                .with(RabbitEnum.register_face.getRouteKey()).noargs();
    }

    @Bean
    public Binding compareBinding(Queue compareQueue, Exchange faceTopic) {
        return BindingBuilder.bind(compareQueue)
                .to(faceTopic)
                .with(RabbitEnum.compare_face.getRouteKey()).noargs();
    }
//    // 新增 verify 相关的 Bean
//    @Bean
//    public TopicExchange verifyTopic() {
//        return ExchangeBuilder.topicExchange(RabbitEnum.verify_code.getExchange()).build();
//    }
//
//    @Bean
//    public Queue verifyQueue() {
//        return new Queue(RabbitEnum.verify_code.getName());
//    }
//
//    @Bean
//    public Binding verifyBinding(Queue verifyQueue, Exchange verifyTopic) {
//        return BindingBuilder.bind(verifyQueue)
//                .to(verifyTopic)
//                .with(RabbitEnum.verify_code.getRouteKey()).noargs();
//    }
}
